﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using Wix.Win8SetupBootstrapper.Annotations;

namespace Wix.Win8SetupBootstrapper.ViewModels
{
    public class PackageItemViewModel: INotifyPropertyChanged
    {
        internal string PackageId { get; set; }

        private bool _isSelected;
        private string _displayName;
        private string _description;
        private List<FeatureItemViewModel> _featuresList;


        public bool IsSelected
        {
            get { return _isSelected; }
            set
            {
                if (value.Equals(_isSelected)) return;
                _isSelected = value;
                OnPropertyChanged();

                if (FeaturesList == null) return;
                foreach (var item in FeaturesList)
                {
                    item.IsSelected = value;
                }
            }
        }

        public string DisplayName
        {
            get { return _displayName; }
            set
            {
                if (value == _displayName) return;
                _displayName = value;
                OnPropertyChanged();
            }
        }

        public string Description
        {
            get { return _description; }
            set
            {
                if (value == _description) return;
                _description = value;
                OnPropertyChanged();
            }
        }


        public List<FeatureItemViewModel> FeaturesList
        {
            get { return _featuresList; }
            set
            {
                if (Equals(value, _featuresList)) return;
                _featuresList = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        [NotifyPropertyChangedInvocator]
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}